package com.sc.web.gwt.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sc.web.gwt.client.GetTokenKeyService;
import com.sc.web.gwt.server.security.OneTimePassword;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * Created by KienCT
 * Date: 29-05-2011
 * Time: 18:47:26
 */
public class GetTokenKeyServiceImpl extends RemoteServiceServlet implements GetTokenKeyService {

    public String getTokenKey() {
        String secretKey = "0979891120";
        long movingFactor = 100;
        try { 
            return OneTimePassword.generateOTP(secretKey.getBytes(), movingFactor, 6, false, 5);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        return "Unexpected Error";
    }
}

